require(multicore)
require(PerformanceAnalytics)
require(quantmod)
require(stockPortfolio)
require(TTR)

# All US stock symbols
SYMs <- TTR::stockSymbols()
workingDir <- getwd()               
setwd("C:\\Projects\\R")


getSymbols("AAPL")
chartSeries(AAPL, subset='last 3 months')
addBBands()
s<- scan(file="C:\\Projects\\R\\ETFs.csv")

zz <- read.csv("C:\\Projects\\R\\ETFs.csv", strip.white = TRUE)
zz <- read.csv(file="C:\\Projects\\R\\ETFs.csv",head = FALSE, sep=",")

getSymbols(c("AAPL","IBM"))
rets <- dailyReturn(AAPL)
getSymbols("DFII10",src="FRED") 

# first do normal VaR calc
VaR(rets, p=.95, method="historical")

# now use Gaussian
VaR(rets, p=.95, method="gaussian")

# now use modified Cornish Fisher calc to take non-normal distribution into account
VaR(rets, p=.95, method="modified")

# now use p=.99
VaR(rets, p=.99)
# or the equivalent alpha=.01
VaR(rets, p=.01)

# now with outliers squished
VaR(rets, clean="boudt")

# add Component VaR for the equal weighted portfolio
VaR(rets, clean="boudt", portfolio_method="component")


